package app.server.project.main.service.dto.cms;

import app.server.project.core.constants.Def;
import app.server.project.core.util.MathUtil;
import app.server.project.main.service.db.entity.cfg.RaceCfgEntity;
import app.server.project.main.service.db.entity.user.UserRaceEntity;
import cn.hutool.core.bean.BeanUtil;
import lombok.Data;

@Data
public class CoinDto {

    private String name;
    private long val;
    private long rate;
    private String clientVal;
    private int tonLock;
    private int raceId;
    private String userId;
    private long addNum;
    private int detailType;


    public static CoinDto of(UserRaceEntity userRaceEntity, RaceCfgEntity raceCfgEntity, long userId) {
        CoinDto coinDto = new CoinDto();
        coinDto.setRaceId(raceCfgEntity.getId());
        BeanUtil.copyProperties(raceCfgEntity, coinDto);
        BeanUtil.copyProperties(userRaceEntity, coinDto);
        coinDto.setUserId(String.valueOf(userId));
        return coinDto;
    }

    public static CoinDto ofAICoin(long val, RaceCfgEntity raceCfgEntity, UserRaceEntity userRaceEntity) {
        CoinDto coinDto = new CoinDto();
        coinDto.setTonLock(userRaceEntity.getTonLock());
        coinDto.setRate(raceCfgEntity.getRate());
        coinDto.setName(raceCfgEntity.getName());
        coinDto.setVal(val);
        return coinDto;
    }

    public void setVal(long val) {
        this.val = val;
        if (val > Def.Zero) {
            this.clientVal = MathUtil.getNumFormat(val, rate);
        } else {
            this.clientVal = "0";
        }

    }
}
